<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Resident_model extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function add_resident($_POST){
		$this->db->query("INSERT INTO resident_basic_info VALUES (
			'".$_POST["student_number"]."',
			'".$_POST["first_name"]."',
			'".$_POST["middle_name"]."',
			'".$_POST["last_name"]."',
			'".$_POST["gender"]."',
			'".$_POST["civil_status"]."',
			'".$_POST["birthday"]."',
			'".$_POST["religion"]."',
			'".$_POST["course"]."',
			'".$_POST["college"]."',
			'".$_POST["classification"]."',
			'".$_POST["home_address"]."',
			'".$_POST["telephone_number"]."',
			'".$_POST["email_address"]."',
			'".$_POST["region"]."'
			)");
		$this->db->query("INSERT INTO resident_extended_info VALUES (
			'".$_POST["student_number"]."',
			'".$_POST["name_of_father"]."',
			'".$_POST["telnumber_of_father"]."',
			'".$_POST["name_of_mother"]."',
			'".$_POST["telnumber_of_mother"]."',
			'".$_POST["name_of_guardian"]."',
			'".$_POST["telnumber_of_guardian"]."'
			)");
	}
	
	function check_resident($_POST){
		return $this->db->query("
			SELECT * FROM resident_basic_info 
			LEFT JOIN resident_extended_info 
			ON resident_basic_info.student_number=resident_extended_info.student_number 
			WHERE resident_basic_info.student_number='".$_POST["student_number"]."'");
	}
	
	function edit_resident($_POST){
		$this->db->query("UPDATE resident_basic_info SET
			first_name='".$_POST["first_name"]."',
			middle_name='".$_POST["middle_name"]."',
			last_name='".$_POST["last_name"]."',
			gender='".$_POST["gender"]."',
			civil_status='".$_POST["civil_status"]."',
			birthday='".$_POST["birthday"]."',
			religion='".$_POST["religion"]."',
			course='".$_POST["course"]."',
			college='".$_POST["college"]."',
			classification='".$_POST["classification"]."',
			home_address='".$_POST["home_address"]."',
			telephone_number='".$_POST["telephone_number"]."',
			email_address='".$_POST["email_address"]."',
			region='".$_POST["region"]."'
			WHERE student_number='".$_POST["student_number"]."'
			");
		$this->db->query("UPDATE resident_extended_info SET
			name_of_father='".$_POST["name_of_father"]."',
			telnumber_of_father='".$_POST["telnumber_of_father"]."',
			name_of_mother='".$_POST["name_of_mother"]."',
			telnumber_of_mother='".$_POST["telnumber_of_mother"]."',
			name_of_guardian='".$_POST["name_of_guardian"]."',
			telnumber_of_guardian='".$_POST["telnumber_of_guardian"]."'
			WHERE student_number='".$_POST["student_number"]."'
			");
	}

	function get_all_residents($_POST){
		return $this->db->query("SELECT * FROM resident_basic_info");
	}
	
	function delete_resident($_POST){
		$this->db->query("DELETE FROM resident_basic_info WHERE student_number='".$_POST['delete']."'");
		$this->db->query("DELETE FROM resident_extended_info WHERE student_number='".$_POST['delete']."'");
	}
	
	function delete_all_residents($_POST){
		$this->db->query("DELETE FROM resident_basic_info");
		$this->db->query("DELETE FROM resident_extended_info");
	}
	
}
/* End of file resident_model.php */
/* Location: ./application/models/resident_model.php */
?>